var gl_vue_vm_list_radio_html = $('#vue_vm_list_radio').html();
var elderBeHospital = {};

$(function() {
	$('#vue_vm_list div').hide();
	$('#vue_vm_list_radio div').hide();
	
	var elderCardId = $.url().param('elderCardId');
	if(elderCardId) {
		$('#searchVal').val(elderCardId);
		findElder($('#searchVal').val(elderCardId));
	}
});

function find_elder_by_elderId() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	
	var elderId = $.url().param('elderId');

	find_basic_by_json(path+'/elder/findDetail', {elderId: elderId}, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getChepingUrl:function(elderId, elderName, elderCardId) {
					return getChepingUrl(elderId, elderName, elderCardId);
				}
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function find_elder_baseInfo(elderType) {
    findElderBeHospital(elderType,path+'/elder/findBaseInfo');
}

function find_elder(elderType) {
    findElderBeHospital(elderType,path+'/elder/find');
}

function findElderBeHospital(elderType,path){
    if($('#vue_vm_list_radio').length==0) {return;}
    $('#vue_vm_list_radio div').hide();
    $('#vue_vm_list').hide();
    $('#inputSection').show();

    var searchVal = $('#searchVal').val();
    if(isEmpty(searchVal)) {
        searchVal = $.url().param('searchVal');
    }

    find_basic_by_json(path, {searchVal: searchVal,elderType:elderType}, function(response) {
        $('#vue_vm_list_radio').html(gl_vue_vm_list_radio_html);

        new Vue({
            el: '#vue_vm_list_radio',
            data: {
                todos: response.data
            },
            methods: {
                getChepingUrl:function(elderId, elderName, elderCardId) {
                    return getChepingUrl(elderId, elderName, elderCardId);
                },
                onFindElderChange:function(elderCardId) {
                    if(findElder) {
                        findElder(elderCardId);
                    }
                },
                onFindElderByElderIDChange:function(elderId) {
                    if(findElderInfoByElderId) {
                        findElderInfoByElderId(elderId);
                    }
                },
                onRadioClick:function() {
                    elderBeHospital.beHospitalId = $('input:radio[name="elderId"]:checked').attr('beHospitalId');
                    elderBeHospital.elderCardId = $('input:radio[name="elderId"]:checked').attr('cardId');
                    elderBeHospital.elderType = $('input:radio[name="elderId"]:checked').attr('elderType');

                    if(autoSearchDetail) {
                        autoSearchDetail(elderBeHospital.elderCardId);
                    }
                    if(elderArrearage_find) {
                        elderArrearage_find(elderBeHospital.elderCardId);
                    }
                },
                onRadioClickElderType:function(elderType) {
                    if(!elderType || elderType!=1) {
                        $('#inputSection').hide();
                        alert('院外长者不能办理入院登记');
                        return;
                    }else {
                        $('#inputSection').show();
                    }
                }
            }
        });

        $('#vue_vm_list_radio div').show();
    });
}
